"""
    Software : PyCharm
    File     : pagenations.py
    Time     : 2021/5/31 18:20
    Author   : Pontoon
    describe :
"""
from collections import OrderedDict
from rest_framework import status
from rest_framework.pagination import PageNumberPagination
from .response import APIResponse


class DefaultPagination(PageNumberPagination):
    # 获取页码数
    page_query_param = 'page'
    # 一页最多显示10条
    page_size_query_param = 'page_size'
    # 默认一页的条数
    page_size = 10
    # 一页最大条数
    max_page_size = 20

    def get_paginated_response(self, data):
        return APIResponse(result=OrderedDict([
            ('count', self.page.paginator.count),
            ('next', self.get_next_link()),
            ('previous', self.get_previous_link()),
            ('results', data)
        ]), status=status.HTTP_200_OK)
